import React from 'react';
import { editusername, addage, Asyncaddage, AsyncsetCollege } from '../../store-rtk/reducers/userReducer'
import { useSelector, useDispatch } from 'react-redux';
const Fun2 = () => {

    const { user } = useSelector((state) => state)
    const dispatch = useDispatch()
    console.log('user', user);
    return (
        <div>
            <button onClick={() => {
                dispatch(editusername('阳过'))
            }}>编辑用户</button>
            <p>{user.username}--{user.age}</p>
            <button onClick={() => {
                dispatch(addage(1))
            }}>编辑年龄</button>
            <button onClick={() => {
                dispatch(Asyncaddage(10))
            }}>异步编辑年龄</button>
            <button onClick={() => {
                dispatch(AsyncsetCollege())
            }}>异步编辑年龄</button>

            <ul>
                {
                    user.collegeArr.map(item => <li key={item.id}>{item.school_name}</li>)
                }

            </ul>
        </div>
    );
}

export default Fun2;
